package com.qunar.wan;

import com.qunar.wan.common_api.model.Activity;
import com.qunar.wan.common_api.model.User;
import com.qunar.wan.common_api.model.enums.EvaluateStatus;
import com.qunar.wan.common_api.service.ActivityService;
import com.qunar.wan.common_api.service.UserActivityService;
import com.qunar.wan.common_api.service.UserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;

/**
 * Created by cyoung on 12/26/13.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring/spring.xml"})
public class Main {
    @Resource
    private UserService userService;
    @Resource
    private UserActivityService userActivityService;
    @Resource
    private ActivityService activityService;

    @Test
    public void test() {
        new Thread(new Thread1()).start();
        new Thread(new Thread2()).start();
        new Thread(new Thread3()).start();

    }
//    @Test
//    public void testSeriz() throws IOException {
////            Activity obj = activityService.selectById(1);
//            FileOutputStream fos = new FileOutputStream("DomainObject");
//            ObjectOutputStream oos = new ObjectOutputStream(fos);
//            oos.writeObject(ActivityState.CANCELED);
//            oos.close();
//            fos.close();
//    }

    class Thread1 implements Runnable {
        Activity activity = activityService.selectById(1);
        User user = userService.selectUserById(1);

        @Override
        public void run() {
            System.out.println(userActivityService.assess(activity, EvaluateStatus.BETTER, user) + "******************");
        }
    }

    class Thread2 implements Runnable {
        Activity activity = activityService.selectById(1);
        User user = userService.selectUserById(1);

        @Override
        public void run() {
            System.out.println(userActivityService.assess(activity, EvaluateStatus.BETTER, user) + "***************");
        }
    }

    class Thread3 implements Runnable {
        Activity activity = activityService.selectById(1);
        User user = userService.selectUserById(1);

        @Override
        public void run() {
            System.out.println(userActivityService.assess(activity, EvaluateStatus.BETTER, user) + "******************");
        }
    }
}


